const nTubeFiltering = {
	DEBUGGING: true,
	CHAPTER_FILTERS: [
		/* Core */
		"Intro",
		"Outro",
		"Sponsor",
	],
	createFilter: function (settingsObject) {
		var isDebugging = nTubeFiltering.DEBUGGING;
		const testContains = function (str, items) {
			for (var i = 0; i < items.length; i++) {
				if (str.toLowerCase().indexOf(items[i].toLowerCase()) > -1) {
					return true;
				}
			}
			return false;
		};
		const testStartsWith = function (str, items) {
			for (var i = 0; i < items.length; i++) {
				if (str.toLowerCase().startsWith(items[i].toLowerCase())) {
					return true;
				}
			}
			return false;
		};
		const testEquals = function (str, items) {
			for (var i = 0; i < items.length; i++) {
				if (str.toLowerCase() === items[i].toLowerCase()) {
					return true;
				}
			}
			return false;
		};
		var data;
		if (Settings.exists("ntube_custom_filter")) {
			data = Settings.load("ntube_custom_filter");
		} else {
			data = null;
		}
		const parsedData = data;
		const n = {
			filterVersion: "indev-06262023",
			/* false: filter NOT triggered, can be used. true: filter triggered, hide content */
			check: function (videoTitle, channelName, isShort) {
				if (isDebugging) {
					console.debug("nTubeFiltering::check -> vt: " + videoTitle + ", cn: " + channelName + ", short: " + isShort);
				}
				if (!isJson(parsedData)) {
					return false;
				}
				if (testEquals(channelName, parsedData["channels"])) {
					return true;
				}
				if (testContains(videoTitle, parsedData["titles"])) {
					return true;
				}
				if (parsedData["shorts"] && isShort) {
					return true;
				}
				return false;
			},
			updateFilterSettings: function (_settingsObject) {},
		};
		return n;
	},
};
window.nTubeFiltering = nTubeFiltering;
